/**
 * @author 黄波
 * 创建日期：2011Sep 20, 2011
 * TODO// N/A
 */
package com.platform.res.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.constant.ResponseCode;
import com.platform.pojo.ResInfo;
import com.platform.res.bo.ResBo;

/**
 * 修改资源信息
 */
public class UpdateResInfoAction extends ResourceSupport {

	private ResInfo item;
	private String id;
	private String msg;
	private boolean success;
	public ResInfo getItem() {
		return item;
	}
	public void setItem(ResInfo item) {
		this.item = item;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	@Override
	public String execute() throws Exception {
		if(id == null || id.equals("")) {
			msg = ResponseCode.FAILURE_ID_NULL;
		} else {
			ResBo bo = ResBo.getInstance();
			item.setId(Integer.parseInt(id));
			if(bo.updateInfo(item)) {
				msg = ResponseCode.SUCCESS_UPDATE;
			} else {
				msg = ResponseCode.FAILURE_UPDATE;
			}
		}
		success = true;
		HashMap map = new HashMap();
		map.put("item", item);
		map.put("msg", msg);
		map.put("success", success);
		JSONObject json = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		out.println(json);
		out.flush();
		out.close();
		return null;
	}
	
	
}
